-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap RET Addresses #10
Conversation
…requires more fixed size BagOfBytes, introducing: Hex64Bytes, Hex65Bytes, Hex33Bytes, generated with macro.
…Key, and same for Secp256k1.
…ove sccache ref in direnv, it did not speed up things.
… in Package.swift, also required for when making releses.
…e, we can make external types such as Scrypto's Decimal Uniffi compat directly contrary to what I initially believed.
…moving the Inner type since it was not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
apple/Sources/UniFFI/Sargon.swift
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize we might actually git rm --cached Sargon.swift
this and then gitignore it. Because it is added part of all releases, and will be present locally...
Hash, | ||
derive_more::Display, | ||
)] | ||
pub struct InnerDecimal(pub(crate) ScryptoDecimal192); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this because I (incorrectly) thought we could not add custom UniFFI conversion for external types, but we can, so no need for this level of indirection.
@@ -88,7 +59,7 @@ pub struct Decimal192 { | |||
/// due to limitations in UniFII as of Feb 2024, but you should | |||
/// create extension methods on Decimal192 in FFI land, translating | |||
/// these functions into methods.) | |||
__inner: InnerDecimal, // Strange field name to try as much as possible hide it in FFI land. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UniFFI did in fact remove __
prefix...
uniffi::Record, | ||
)] | ||
#[display("{secret_magic}")] | ||
pub struct AccessControllerAddress { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declare "manually" and NOT by macro so we can add documentation to it! which is not possible with macro_rules!
(or at least too hard for me...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah wrong! we CAN include doc strings in macros, change incoming.
) -> Result<Self>; | ||
} | ||
|
||
macro_rules! decl_ret_wrapped_address { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This macro creates the needed UniFFI converter for each RET address, using String
as Builtin
type. It impl From
the wrapped RET address type into the Sargon address type. and all UniFFI exported function
RetAccessControllerAddress, | ||
accesscontroller | ||
); | ||
decl_ret_wrapped_address!(AccountAddress, RetAccountAddress, account); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N.B. the actual Sargon address types, e.g. AccountAddress
, PackageAddress
etc are defined in other files, outside of the macro, so that we can add documentation to them, which is not possible to "inject" into macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah wrong! we CAN include doc strings in macros, change incoming.
src/sargon.udl
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunate but, c'est la vie, declaring the Ret canonical address as UniFFI convertible via String make implementation of our wrapping of these types easy and allows for safe Rust code, and safe Swift/Kotlin models, so best of two worlds, at the cost of having to declare them here in the UDL file...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very very nice 👏!
@@ -9,6 +9,7 @@ extend-exclude = [ | |||
|
|||
[default.extend-identifiers] | |||
inout = "inout" | |||
pool_tdx_2_1c4ml86h8lvfk7jma0jy0vksh8srcxhmtax8nd3aur29qtd2k2wmlzk = "pool_tdx_2_1c4ml86h8lvfk7jma0jy0vksh8srcxhmtax8nd3aur29qtd2k2wmlzk" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typos CLI tool corrected that address 😅😅 so had to ignore it
@@ -19,37 +19,8 @@ use radix_engine_common::types::EntityType as ScryptoEntityType; | |||
)] | |||
#[repr(u32)] // it is u32 since used in Derivation Paths (CAP26) where each component is a u32. | |||
pub enum AbstractEntityType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is meant only to describe an Entity in the sense of either Account or Identity, but not other address kind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, account or identity only. I can see if I can remove this perhaps
|
||
#if DEBUG | ||
/// TODO: Declare in Rust land? Make non-DEBUG? | ||
public enum Address: Hashable, Equatable, Sendable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will most probably be needed in the iOS Wallet, where we do need to merge together different kinds of addresses in some places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be added in Rust land immediately when I see we really need it. I still - naive perhaps - think we can avoid having it in wallets. Or at least a smaller tagged union (fewer cases)
UniFFI macro invocations introduces a lot of false negatives, decreasing the accuracy in reported code coverage, I've asked about if we can improve accuracy in xd009642/tarpaulin#351 (comment) Will merge this PR as is, nothing we can do. |
Increase code coverage further
I've removed the huge Sargon.swift file and gitignored it since I believe we don't need it checked in to git, see gitignore for rationale.
This PR vendors wrapping of RET's new Canonical*Address types, specifically:
Also simplify how Decimal192 is implemented, removing one level of indirection.
All addresses have been fully Swiftified on the Swift side, including preview values.
The "interface" of ALL address is this (swift version)